<?php 
namespace Home\Model;
use Think\Model\ViewModel;
class ArticleViewModel extends ViewModel{
	public $viewFields = array(
		'article'=>array('id','title','content','thumb','date','tags','views','user_id','cate_id','top'),
		'category'=>array('name'=>'cate_name','slug','keywords','description','_on'=>'article.cate_id=category.id'),
		'member'=>array('username','_on'=>'article.user_id=member.id'),
	);

	public function getAticles($slug="",$order,$number){
		if(empty($slug)){
		
			$count = $this->count();
			$Page  = new \Library\Page($count,$number);// $number为分页数
			$Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% <li>%HEADER%</li>');
			$data['page'] = $Page->show();// 分页显示输出
			$data['article'] =
			       $this->order($order)
						->limit($Page->firstRow.','.$Page->listRows)
						->select();
			return $data;


		}else{

			$count = $this->where("category.slug='".$slug."'")->count();
			$Page  = new \Library\Page($count,$number);// $number为分页数
			$Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% <li>%HEADER%</li>');
			$data['page'] = $Page->show();// 分页显示输出
			$data['article'] =
			       $this->where("category.slug='".$slug."'")
						->order($order)
						->limit($Page->firstRow.','.$Page->listRows)
						->select();
			return $data;
		}
		
	}
}

 ?>